package YAPserver.mods;

import java.util.ArrayList;
import java.util.Random;

import YAPenvironment.YAPconstant.ModState;
import YAPserver.gameObjects.Mod;
import YAPserver.gameObjects.Point;
import YAPserver.logic.GameModifier;
import YAPserver.logic.Player;

/**
 * A global modBehaviour.
 * This modBehaviour is very similar to ModEightBall. This class creates nine small fast mods that either
 * subtract a life or add a life to the player it hits. These small mods have either a ModAddLife or a ModSubtractLife behaviour.
 * @author Daniel
 */
public class ModNineBall extends AbstractStandardMod{

	@Override
	public void modify(Mod mod, GameModifier gameMod, Player player) {
		super.modify(mod, gameMod, player);
		//now for some fun
		//this is the point my 9 balls will radiate from
		Point middlePoint = new Point(gameMod.getBalls(0).getMiddlePoint());
		double angle = gameMod.getBalls(0).getLine().getAngle();
		
		//a list for the balls, so we can check collisions afterwards
		ArrayList<Mod> mods = new ArrayList<Mod>();
		Random rand = new Random();
		for(int i=0; i<9; i++){
			ModBehaviour modB;
			if(rand.nextBoolean()){
				modB = new ModAddLife();
			}else{
				modB = new ModSubtractLife();
			}
			mods.add(new Mod(new Point(middlePoint), 2.*Math.PI/9.*i+angle, 9, 3, 
					gameMod, modB));
		}
		gameMod.checkCollisions(mods);
		for(int i=0; i<9; i++){
			gameMod.addModMoving(mods.get(i));
		}
	}

	@Override
	public void deModify(Mod mod, GameModifier gameMod, Player player) {
		// TODO Auto-generated method stub

	}

	@Override
	public ModState getType() {
		return ModState.global;
	}

}
